<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018-12-22
  Time: 上午 9:26
  商品信息编辑页
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.4.5/layui/layui.js" charset="utf-8"></script>
    <script src="/js/layui/form_verify.js"></script>
    <link rel="stylesheet" href="../../layui-v2.4.5/layui/css/layui.css" media="all">
</head>
<body style="width: 425px;">
<textarea id="demo" style="display: none;  ">
    ${content}
</textarea>

<button class="layui-btn" style="margin-left: 40%" onclick="saveMessage()">保存</button>
<script>
    var layedit;
    var index;
    layui.use('layedit', function(){

        layedit = layui.layedit;

        layedit.set({
            uploadImage: {
                url: '/shop/commodityParticularsImgUpload?commodityId=${commodityId}' //接口url
                ,type: 'post' //默认post
            }
        });

        index=layedit.build('demo',{
            height: '80%',//设置编辑器高度
            tool: [
                'strong' //加粗
                ,'italic' //斜体
                ,'underline' //下划线

                ,'|' //分割线

                ,'left' //左对齐
                ,'center' //居中对齐
                ,'right' //右对齐
                ,'image' //插入图片

            ]
        }); //建立编辑器





    });


    function saveMessage() {
        var cont=layedit.getContent(index);
        //console.log(cont);
        $.ajax({
            url:'/shop/saveParticularsContent',
            type:'POST', //GET
            async:true,    //或false,是否异步
            data:{
                commodityId:'${commodityId}',
                content:cont
            },
            timeout:5000,    //超时时间
            dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend:function(xhr){
                /*console.log(xhr)
                console.log('发送前')*/
            },
            success:function(data){
                console.log(data);

                if (data.code=='000000'){
                    layer.msg(data.msg,{time:1000,icon: 6},function () {
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        window.location.href=location.href;
                    });
                }else {
                    layer.msg(data.msg,{time:1000,icon: 5});
                }

            },
            error:function(xhr,textStatus){
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete:function(){
                //console.log('结束')
            }
        })


    }
    
    
</script>
</body>
</html>
